package cn.cdqf.coupon.dispatch.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class FeignController {
    @Autowired
    private RestTemplateControllerApi restTemplateControllerApi;
    @GetMapping("feignTest")
    @HystrixCommand(fallbackMethod = "fallback")
    public String feignTest(){
        return restTemplateControllerApi.restTemplate();
    }

    @GetMapping("hystrix")
    @HystrixCommand(fallbackMethod = "fallback")
    public String hystrix(Integer code){
        log.info("hystrix方法获得参数："+code);
        if(code==0){
            throw new RuntimeException();
        }
        return "success";
    }
    //与被降级的方法参数跟返回值必须相同
    private String fallback(){
        log.info("fallback方法获得参数：");
        return "sorry 网络开小差了";
    }
}
